<?php
/**
 * ResMania
 * More Information contact: info@resmania.com
 *
 * @package Joomla Main Admin File
 * @version 0.5
 * @author webformatique
 * @copyright (C) 2010- webformatique
 * @license GNU/GPLv3 http://www.gnu.org/copyleft/gpl.html
 */
defined( '_JEXEC' ) or die( 'Restricted access' );

require_once dirname(__FILE__).DS."installation".DS."model".DS."install.check.class.php";
if ((isset($_REQUEST['act']) && $_REQUEST['act'] === 'install') || ResMania_Installer_Check::checkInstalled()===false){
    /*
     * This section is used for installation only...
     */
    require_once dirname(__FILE__).DS."installation".DS."model".DS."install.class.php";
    require_once dirname(__FILE__).DS."installation".DS."controller".DS."install.controller.php";
    require_once dirname(__FILE__).DS."installation".DS."view".DS."helper.php";

    if (!isset($_REQUEST['task'])) ResMania_Install_View::withView(); // if act = install and task = null render the html

    /**
     * this code checks if the version number is passed on the url string. We
     * have to write to a cookie so that the value is available to the ajax
     * request.
     */
    $overrideVersion = false;
    $cookieVar = false;
    if (isset($_REQUEST['version'])){$overrideVersion = $_REQUEST['version'];}
    if (isset($_COOKIE["rm-core-install-version"])){$cookieVar = $_COOKIE["rm-core-install-version"];}
    if (($cookieVar!=$overrideVersion || $cookieVar==null) && $overrideVersion!=null){
        setcookie("rm-core-install-version",$overrideVersion, date("U")+180);
    } else {
        $overrideVersion = $cookieVar;
        setcookie("rm-core-install-version",$overrideVersion, date("U")+180); // reset the cookie timeout value so that it does not expire
    }

    ResMania_Installer_Check::InstallSwitch($overrideVersion); // this is mainly used for handling the ajax requests.

} else {

    // this redirects the gui using maximised or minimum settings...
    $db =& JFactory::getDBO();
    $query = "SELECT value FROM rm_config WHERE id='rm_config_admin_gui_maximised' LIMIT 1";
    $db->setQuery( $query );
    $Maximised = (int)$db->loadResult(); // 1 = maximised

    require_once dirname(__FILE__) . DS . 'classes' . DS . 'RM' . DS . 'Joomla' . DS . 'Connector.php';
    if ($Maximised == 1 &&
        !isset($_REQUEST['task']) &&
        !isset($_REQUEST['act'])) {

        if (RM_Joomla_Connector::is16()) {
            if (isset($_REQUEST['format']) == false) {
                $app  = & JFactory::getApplication();
                $app->redirect('index.php?option=com_resmania&format=raw'); //redirect
            }
        } elseif (RM_Joomla_Connector::is15()) {
            if (substr_count($_SERVER["REQUEST_URI"], "index3.php") == 0) {
                global $mainframe;
                $mainframe->redirect('index3.php?option=com_resmania');
            }
        }
    }

        // load Joomla 1.6 specific CSS
    if (RM_Joomla_Connector::is16()) {
        $document =& JFactory::getDocument();
        $document->addStyleSheet(JURI::base().'components/com_resmania/joomla16.css');
    }

    // load the Application
    RM_Connector::setup('RM_Joomla_Connector', 'admin');
    $connector = RM_Connector::getInstance();
    $connector->connect();
}
?>
<!-- this style hides the joomla toolbar to maximise the content area -->
<style type="text/css">
#toolbar-box div.m {display: none;}
</style>